// pages/termDetail/index.js
import { request } from '../../request/index'
Page({
  buy: function (e) {
    wx.navigateTo({
      url: '/pages/buyTerm/index?item=' + JSON.stringify(this.data.term[e.currentTarget.dataset.id])
    })
  },
  /**
   * 页面的初始数据
   */
  data: {
    position: -1,
    person: {
      // name: '薪子',
      // avatar: 'http://129.28.168.85/img/1.png',
      // priaseDegree: 100,
      // lessonNumber: 715,
      // isEmpty: true,
    },
    term: [
      // { imgUrl: "http://129.28.168.85/img/1.png", price: 100, name: '私教体验课', content: '360度全面身体评估，私人定制训练课程' },
      // { imgUrl: "http://129.28.168.85/img/1.png", price: 223, name: '增肌max', content: '360度全面身体评估，私人定制训练课程' },
      // { imgUrl: "http://129.28.168.85/img/1.png", price: 132, name: '减脂塑形', content: '360度全面身体评估，私人定制训练课程' },
      // { imgUrl: "http://129.28.168.85/img/1.png", price: 323, name: '三节课速成', content: '360度全面身体评估，私人定制训练课程' },
    ],
    comments: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var app = getApp()
    var person = JSON.parse(options.content)
    this.setData({
      position: app.globalData.position,
      person: person,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var app = getApp()
    request({ url: app.globalData.root + 'api/termsFind', method: 'GET', data: { userId: this.data.person.userId }, dataType: 'json' }).then((rsl) => {
      rsl.data.forEach((item,index)=>{
        item.imgUrl = app.globalData.root + 'img/' + item.imgUrl
      })
      this.setData({
        term: rsl.data
      })
    })

    request({ url: app.globalData.root + 'api/commentsFind', method: 'GET', data: { coachId: this.data.person.userId }, dataType: 'json' }).then((rsl) => {
      var app = getApp()
      rsl.data.forEach((item,index)=>{
        var time = new Date(item.createTime)
        item.createTime = `${time.getFullYear()}-${time.getMonth()+1}-${time.getDate()} ${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`
      })
      this.setData({
        comments:rsl.data
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})